package behaviour;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import pacman.Ghost;

import simulation.Simulator;

import maze.Coordinate;
import maze.Direction;
import maze.Location;
import maze.Maze;

public class Explorer02 implements Strategy {

	private Coordinate currentCoordinate;
	private ArrayList<Direction> path = new ArrayList<Direction>();
	private Maze maze;
	public Simulator sim;
	public Ghost g;

	public Explorer02(Maze maze) {

		this.maze = maze;
	}

	@Override
	public Direction nextDirection(Location loc, Maze[] mazes, Coordinate[] ghosts) {
		Direction ret = null;

		Coordinate coord = maze.getCoordinateOfLocation(loc);

		Direction[] directions = new Direction[4];
		directions[0] = Direction.NORTH;
		directions[1] = Direction.EAST;
		directions[2] = Direction.SOUTH;
		directions[3] = Direction.WEST;

		for (int i = 0; i < directions.length; i++) {
			ret = directions[i];
			Coordinate localcoord = Coordinate.getCoordinateInDirection(coord,
					ret);
			Coordinate simCoord = sim.getMaze().getCoordinateOfLocation(
					sim.getGhostLocations().get(g));
			if (maze.hasThisSectorExplored(localcoord))
				ret = null;
			else if (sim.getMaze().read(simCoord.getX(), simCoord.getY(), ret,
					true) == 1)
				ret = null;
			else
				return ret;
		}

		while(ret == null)
		{
			int i = (int)(Math.random()*3+0.5);
			ret = directions[i];
			Coordinate simCoord = sim.getMaze().getCoordinateOfLocation(sim.getGhostLocations().get(g));
			if (sim.getMaze().read(simCoord.getX(), simCoord.getY(),ret, true) == 1)
				ret = null;	
		}
		

		return ret;
	}

	@Override
	public boolean exploreEverything() {
		// TODO Auto-generated method stub
		return false;
	}

}
